package com.fauks.study.msstart.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class QuickStartController {

    /**
     * 传统路径重写方式请求 xxx?msg=xxx
     */
    @RequestMapping(value = "/echo1", method = RequestMethod.GET)
    public String echo1(String msg) {
        return "{echo1} hello-" + msg;
    }

    /**
     * rest风格访问 xxx/echo/xxx
     * 只接受GET请求
     * 可以在参数中直接注入jsp内置对象
     */
    @RequestMapping(value = "/echo2/{message}", method = RequestMethod.GET)
    public String echo2(@PathVariable("message") String msg, HttpServletRequest request) {
        String remoteAddr = request.getRemoteAddr();
        return "{echo2} hello-" + msg;
    }
}
